package top.superflow.core.semantic

import scala.annotation.StaticAnnotation
import scala.collection.immutable._
import scala.language.experimental.macros
import scala.meta._

class Semantic extends StaticAnnotation {
//  inline def apply(defn: Any): Any = meta {
//
//    val q"..$mods object $name extends ..$inits { $self => ..$stats }" = defn
//    val main = q"def main(args: Array[String]): Unit = { ..$stats }"
//    q"..$mods object $name extends ..$inits { $self => $main }"
//  }
//  inline def apply(defn: Any): Any = meta {
//    defn match {
//      case q"..$mods class $tname[..$tparams]  " =>
//        q"..$mods class $tname[..$tparams]"
//      case _ =>
//        abort("@main must annotate an object.")
//    }
//  }

//  inline def apply(defn: Any): Any = meta {
//    defn match {
//      case q"..$mods class $tname[..$tparams] ..$ctorMods (...$paramss) extends $template { $self => ..$stats }" =>
//        q"..$mods class $tname[..$tparams] ..$ctorMods (...$paramss) extends $template { $self => ..$stats }"
//      case _ =>
//        println(defn.structure)
//        abort("@Class2Map must annotate abcc class." + defn.structure)
//    }
//  }
}

object MainMacroImpl {
//  def expand(name: Term.Name, stats: Seq[Stat]): Defn.Object = {
//    val main = q"def main(args: Array[String]): Unit = { ..$stats }"
//    q"object $name { $main }"
//  }
}
object ClassOrTrait {
  def unapply(any: Defn): Option[(Seq[Mod], Type.Name)] = any match {
    case t: Defn.Class => Some((t.mods, t.name))
    case t: Defn.Trait => Some((t.mods, t.name))
    case _ => None
  }
}
object MacroUtil {
  def helper(defn: Any): Stat = q"class SemanticTest"
}
//extends StaticAnnotation {
//  val dummy=2
//
//
//  inline def apply(defn: scala.meta.Tree): Any =  {
//    defn match {
//      case q" ..$mods class $name(..$params) { ..$stats }" =>
//        q"""
//        ..$mods class $name(..$params) {
//      def toMap(): Map[String, Any] = Map.empty[String, Any]
//           ..$stats
//    }
//  """
//      case _ =>
//        throw new RuntimeException("")
//    }
//  }
//}


//object SemanticImpl {
////  def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
////    import c.universe._
////    val result = annottees map (_.tree) match {
////      // Match a class, and expand.
////      case (q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }") :: _ =>
////
////          q"""
////            $mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self =>
////
////              def sayHello: Unit = {
////                           println("Hello I'm  and my name is" )
////                         }
////              ..$stats
////            }
////          """
////      // Not a class.
////      case _ => c.abort(c.enclosingPosition, "Invalid annotation target: not a class")
////    }
////    c.Expr[Any](result)
////
////  }
//}